﻿namespace Cos.Module.Form.NHibernate.Test
{
    using System;
    using System.Collections.Generic;

    using Cos.Core.NHibernate;
    using Cos.Core.NHibernate.Tests;

    using NUnit.Framework;

    public class ModuleFixtureBase :FixtureBase
    {
        public CultureDataModel Culture;
        public FormDataModel Form;
        public FormPageDataModel FormPage;
        public FormElementDataModel FormElement;
        public FormElementChoiceDataModel FormElementChoice;
        public SubmissionDataModel Submission;
        public SubmissionValueDataModel SubmissionValue;

        public ModuleFixtureBase() : base(new TestModel())
        {
            this.Form = new FormDataModel
            {
                AnswerOnce = false,
                ApprobationDate = new DateTime(2011, 01, 04),
                Author = "Bill Smith",
                ConfirmEmail = string.Empty,
                CreationDate = new DateTime(2011, 01, 04),
                CSS = string.Empty,
                DisplayType = "LabelLeft",
                EmailFrom = "test@cameleon.com",
                //FormCultures = new List<FormCultureDataModel>(),
                //FormElements = new List<FormElementDataModel>(),
                //FormPages = new List<FormPageDataModel>(),
                IsDeleted = false,
                Kickback = null,
                LastModifiedDate = new DateTime(2011, 01, 04),
                Name = "Form",
                PageCss = string.Empty,
                ReturnUrl = string.Empty,
                SelectedPageCss = string.Empty,
                ShowAsSurvey = false,
                ShowSummary = false
            };

            this.FormPage = new FormPageDataModel
            {
                //FormElements = new List<FormElementDataModel>(),
                //FormPageCultures = new List<FormPageCultureDataModel>(),
                FormId = this.Form.Id,
                IsDeleted = false,
                Ordering = 0
            };

            this.FormElement = new FormElementDataModel
            {
                Boolean1 = true,
                Boolean1Live = true,
                Boolean2 = true,
                Boolean2Live = true,
                CSS = "css",
                CssLive = "css live",
                Enum = "enum",
                EnumLive = "enum live",
                //FormElementChoices = new List<FormElementChoiceDataModel>(),
                //FormElementCultures = new List<FormElementCultureDataModel>(),
                FormId = this.Form.Id,
                FormPageId = this.FormPage.Id,
                InputType = "Text",
                IsDeleted = false,
                Long1 = 1.0,
                Long1Live = 1.1,
                Long2 = 2.0,
                Long2Live = 2.1,
                Long3 = 3.0,
                Long3Live = 3.1,
                Long4 = 4.0,
                Long4Live = 4.1,
                Name = "name",
                Ordering = 1,
                Required = true,
                RequiredLive = true,
                //SubmissionValues = new List<SubmissionValueDataModel>(),
                Text1 = "text 1",
                Text1Live = "text 1 live",
                Text2 = "text 2",
                Text2Live = "text 2 live"
            };

            this.FormElementChoice = new FormElementChoiceDataModel
            {
                //FormElementChoiceCultures = new List<FormElementChoiceCultureDataModel>(),
                FormElementId = this.FormElement.Id,
                IsDeleted = false,
                Ordering = 1,
                Value = "value"
            };

            this.Culture = new CultureDataModel
            {
                Id = "fr-CA",
                CultureDesc = string.Empty,
                IsDefault = true
            };

            this.Submission = new SubmissionDataModel
            {
                CultureCode = this.Culture.Id,
                Email = "email",
                FormId = 1,
                IP = "127.0.0.1",
                PageUrl = "page url",
                ReferenceUrl = "reference url",
                SubmissionDate = new DateTime(2011, 01, 04)
            };

            this.SubmissionValue = new SubmissionValueDataModel
            {
                FormElementId = this.FormElement.Id,
                //SubmissionValueItems = new List<SubmissionValueItemDataModel>(),
                SubmissionId = this.Submission.Id,
                Value = "value"
            };
        }

        [TestFixtureSetUp]
        public void ModuleSetupContext()
        {
            using (var tx = this.Session.BeginTransaction())
            {
                this.Session.SaveOrUpdate(this.Culture);
                this.Session.SaveOrUpdate(this.Form);
                this.Session.SaveOrUpdate(this.FormPage);
                this.Session.SaveOrUpdate(this.FormElement);
                this.Session.SaveOrUpdate(this.FormElementChoice);
                this.Session.SaveOrUpdate(this.Submission);
                this.Session.SaveOrUpdate(this.SubmissionValue);

                tx.Commit();
            }

            this.Session.Flush();
            this.Session.Clear();
        }
    }
}
